package cn.smbms.service.user;

import cn.smbms.dao.user.UserMapper;
import cn.smbms.pojo.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service("userService")
public class UserServiceImpl implements UserService {
	@Resource
    private UserMapper userMapper;

	@Override
	public User login(String userCode, String userPassword) throws Exception {
		User user = null;
		user = userMapper.getLoginUser(userCode);
		//匹配密码
		if(null != user){
			if(!user.getUserPassword().equals(userPassword))
				user = null;
				
		}
		return user;
	}

	@Override
	public int getUserCount(String queryUserName, int queryUserRole) {
		
		int count = 0;
		System.out.println("queryUserName ---- > " + queryUserName);
		System.out.println("queryUserRole ---- > " + queryUserRole);
		count = userMapper.getUserCount(queryUserName,queryUserRole);
		return count;
	}
	
	public List<User> getUserList(String queryUserName, int queryUserRole,
			int currentPageNo, int pageSize) {
		int beginIndex = (currentPageNo-1)*pageSize;
		return userMapper.getUserList(queryUserName, queryUserRole, beginIndex,
				pageSize);
	}

	@Override
	public int add(User user) {
		return userMapper.add(user);
	}

	@Override
	public List<User> getUserById(User user) {
		return userMapper.getUserById(user);
	}

}
